package cn.tedu.system.live.controller;

import cn.tedu.system.base.response.JsonResult;
import cn.tedu.system.live.pojo.dto.LiveRoomParam;
import cn.tedu.system.live.pojo.entity.LiveRoom;
import cn.tedu.system.live.pojo.vo.LiveRoomVO;
import cn.tedu.system.live.service.LiveService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@Api(tags = "08.直播模块")
@RestController
@RequestMapping("/api/v1/live/")
public class LiveController {
    @Autowired
    private LiveService liveService;

    @ApiOperation("创建直播")
    @ApiOperationSupport(order = 10)
    @PostMapping("start")
    public JsonResult createRoom(@RequestBody LiveRoomParam live, @ApiIgnore HttpSession session) {
        log.debug("创建直播业务参数:{}", live);
        Long id = liveService.createLiveRoom(live,session);
        return JsonResult.ok(id);
    }

    @ApiOperation("获取指定ID的直播房间详情")
    @ApiOperationSupport(order = 20)
    @GetMapping("room")
    public JsonResult getRoom(Long id) {
        log.debug("获取直播房间详情参数:{}", id);
        LiveRoomVO room = liveService.getLiveRoomById(id);
        return JsonResult.ok(room);
    }

    @ApiOperation("查看所有直播")
    @ApiOperationSupport(order = 30)
    @GetMapping("rooms")
    public JsonResult getLiveRooms() {
        log.debug("获取所有直播房间");
        List<LiveRoomVO> rooms = liveService.getLiveRooms();
        return JsonResult.ok(rooms);
    }

    @ApiOperation("停止直播")
    @ApiOperationSupport(order = 60)
    @PostMapping("stop")
    public JsonResult stopLive(Long id) {
        log.debug("停止直播参数:{}", id);
        liveService.stopLive(id);
        return JsonResult.ok();
    }

//    @ApiOperation("获取直播房间列表（可按状态筛选）")
//    @ApiOperationSupport(order = 30)
//    @GetMapping("/rooms")
//    public JsonResult getLiveRooms(@RequestParam(required = false) Integer status) {
//        log.debug("获取直播房间参数:{}",status);
//        List<LiveRoom> rooms;
//        if (status != null) {
//            rooms = liveService.getLiveRoomsByStatus(status);
//        } else {
//            // 默认获取正在直播的房间
//            rooms = liveService.getLiveRoomsByStatus(1);
//        }
//        return JsonResult.ok(rooms);
//    }

//    @ApiOperation("获取指定用户的所有直播房间")
//    @ApiOperationSupport(order = 40)
//    @GetMapping("/user/{userId}/rooms")
//    public JsonResult getUserRooms(@PathVariable Long userId) {
//        List<LiveRoom> rooms = liveService.getUserLiveRooms(userId);
//        return JsonResult.ok(rooms);
//    }

//    @ApiOperation("开始直播（更改房间状态为直播中）")
//    @ApiOperationSupport(order = 50)
//    @PostMapping("/room/{roomId}/start")
//    public JsonResult startLive(@PathVariable Long roomId) {
//        liveService.startLive(roomId);
//        return JsonResult.ok();
//    }
}
